Ext.namespace("MyPlan");

MyPlan.ToAudit = function() {
	this.winViewPlan = null;
	this.store = new Ext.data.JsonStore({
	    url: Utils.formatURL('../myplan/toAuditPlan.form?timesnap=' + Date.parse(new Date())),
	    root: 'result',
	    fields: ['planId', 'planName','planType','createId','createName','auditorName','startDate','endDate','planState']
	});
	this.renderType = function(value){
		return OMS.PLANTYPE[value];
	};
	this.renderExport=function(value){
		var url='../auditplan/exportPlan.form?planId='+value+'&timesnap=' + Date.parse(new Date());
		return '<a href="'+url+'" >导出</a>';
	}
	this.column = [
		  {header: '计划编号', sortable: true, align: 'left',hidden:true, dataIndex: 'planId'},
		  {header: '创建人ID', sortable: true, align: 'left',hidden:true, dataIndex: 'createId'},
		  {header: '创建人名称', sortable: true, align: 'left',hidden:true, dataIndex: 'createName'},
	      {header: '计划名称', sortable: true, align: 'left', dataIndex: 'planName'},
	      {header: '计划类型', sortable: true, align: 'center', width: 20, dataIndex: 'planType',renderer:this.renderType},
	      {header: '开始时间', sortable: true, align: 'center', width: 20, dataIndex: 'startDate'},
	      {header: '结束时间', sortable: true, align: 'center', width: 20, dataIndex: 'endDate'},
	      {header: '审核人', sortable: true,width: 40, align: 'left',dataIndex: 'auditorName'},
	      {header: '导出',  align: 'center',width: 40, dataIndex: 'planId',renderer:this.renderExport}
	];
	this.bbar=new Ext.PagingToolbar({
		 pageSize: 15,
         store: this.store,
         displayInfo: true,
         displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
         emptyMsg: "没有记录..."
	});
	this.btnSearch = new Ext.Toolbar.Button({
        iconCls: 'icon-search',
        text: '查找',
        tooltip: {text: '查找计划'},
        handler: this.queryPlan,
        scope: this
    });
	MyPlan.ToAudit.superclass.constructor.call(this, {
		title: '待审核计划',
        region: 'center',
        tbar: ['->',this.btnSearch],
        cm: new Ext.grid.ColumnModel(this.column),
        sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
        bbar:this.bbar,
        store:this.store,
        viewConfig: { forceFit: true },
        listeners:{
			//render:this.queryPlan,
			activate: this.queryPlan,
			rowdblclick : this.onViewPlan
		}
    });
};
Ext.extend(MyPlan.ToAudit, Ext.grid.GridPanel, {
	queryPlan:function(btn,event){
		this.store.load({
			params:{
				start : 0,
				limit : 15
				}
		});
	},
	onViewPlan:function(grid, rowIndex,e){		
		if (this.winViewPlan == null) {
			this.winViewPlan = new MyPlan.WeeklyView(this);
		}
		this.winViewPlan.show();
		this.winViewPlan.initWin(grid.store.getAt(rowIndex).data);		
	}
});
